package com.company.goodfuture2021;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Main12 {
    public String notReCuPreOrder (TreeNode root) {
        // write code here
        String res = "";
        if(root == null){
            return res;
        }
        Stack<TreeNode> stack = new Stack<>();
        stack.push(root);
        List<Integer> array = new ArrayList<>();
        while (!stack.isEmpty()){
            TreeNode t = stack.pop();
            array.add(t.val);
            if(t.right != null){
                stack.push(t.right);
            }
            if(t.left != null){
                stack.push(t.left);
            }
        }
        StringBuilder str = new StringBuilder();
        for (int i = 0; i < array.size(); i++) {
            if(i != 0){
                str.append(",");
            }
            str.append(array.get(i));
        }
        return str.toString();
    }
}
